﻿namespace Web.Control.WWW.Group
{
    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using Lx.Web.Common.ControlsUI;
    using System.Collections;
using Model.WWW_WWW.Group;
using System.Collections.Generic;


    /// <summary>
    /// EditGroup 的摘要说明
    /// </summary>
    public class Members : BaseControl
    {
        protected string gid = "";
        /// <summary>
        /// 组信息
        /// </summary>
        protected GroupModel gm;
        /// <summary>
        /// 标签列表
        /// </summary>
        protected List<string> tagList;
        /// <summary>
        /// 管理员列表
        /// </summary>
        protected List<MemberModel> adminList;
        /// <summary>
        /// 当前会员编号
        /// </summary>
        protected string Memberno = "";
        /// <summary>
        /// 当前会员昵称
        /// </summary>
        protected string NickName = "";
        /// <summary>
        /// 绑定成员数据
        /// </summary>
        protected Repeater rptMembers;
        /// <summary>
        /// 数据数量
        /// </summary>
        protected int RecordCount = 0;
        protected int PageIndex = 1;               
        protected Literal litCount;
        /// <summary>
        /// 排序：1：默认Right、2：last login、4：Posts
        /// </summary>
        protected string SortOrder = "1";

        protected override void OnLoad(EventArgs e)
        {
            Memberno = HttpContext.Current.User.Identity.Name;  
            if (!string.IsNullOrEmpty(Request["gid"]))
            {
                gid = Request["gid"];
            }
            else
            {
                Response.End();
                return;
            }
            if (!string.IsNullOrEmpty(Request["p"]))
            {
                if (Request["page"] == "L")
                {
                    PageIndex = 999;
                }
                else
                {
                    int.TryParse(Request["p"], out PageIndex);
                    if (PageIndex == 0)
                    {
                        PageIndex = 1;
                    }
                }
            }
            if (!string.IsNullOrEmpty(Request["SO"]))
            {
                SortOrder = Request["SO"];
            }
            int psize = 15;
            if (litCount != null) int.TryParse(litCount.Text, out psize);
            ArrayList arrList;
            if (Memberno!=""&&!string.IsNullOrEmpty(Request["Flag"]) && !string.IsNullOrEmpty(Request.Form["OPID"]) && !string.IsNullOrEmpty(Request.Form["ReMID"]))
            {                
                int op;
                int.TryParse(Request.Form["OPID"], out op);
                arrList = BLF.WWW_WWW.Group.Group.GetGroMembers(gid, Memberno, PageIndex, psize, Request.Form["ReMID"], op, SortOrder);
            }
            else
            {
                arrList = BLF.WWW_WWW.Group.Group.GetGroMembersOrder(gid, Memberno, PageIndex, psize, SortOrder);
            }            
            if (arrList != null && arrList.Count > 1)
            {
                gm = arrList[0] as GroupModel;
                RecordCount = (int)arrList[4];
                int pCount = (int)Math.Ceiling(((decimal)RecordCount) / ((decimal)psize));
                if (PageIndex > pCount) PageIndex = pCount;
                tagList = arrList[1] as List<string>;
                adminList = arrList[2] as List<MemberModel>;
                NickName = (string)arrList[5];
                if (rptMembers != null)
                {
                    rptMembers.DataSource = arrList[3];
                    rptMembers.DataBind();
                }
                //标题
                this.DynamicTitle = GetText("GP528", new string[] { gm.Title });
                if (gm.Language1 != "")
                {
                    this.DynamicKeywords = GetText("GP529", new string[] { BLF.StaticData.GetLanguageText(gm.Language1), BLF.StaticData.GetLanguageText(gm.Language2) });
                }
                else
                {
                    this.DynamicKeywords = GetText("GP564", new string[] { BLF.StaticData.GetLanguageText(gm.Language2) }); 
                }
                this.DynamicDescription = GetText("GP530", new string[] { gm.Title });
            }
            else
            {
                Response.End();
            }
            base.OnLoad(e);
        }
        /// <summary>
        /// 获取页面状态操作内容 1：创建者、2：管理员、3：成员、9:申请管理员、8：申请会员
        /// </summary>
        /// <param name="value"> 1：创建者、2：管理员、3：成员、9:申请管理员、8：申请会员</param>
        /// <param name="memberno">会员编号</param>
        /// <returns>返回页面文本</returns>
        protected string GetPStateOP(string value, string memberno)
        {
            string content = "";
            //if (memberno == Memberno)
            //{
            //    content = GetText("GP226");
            //}
            //else
            //{//0无操作、1批准管理员、2批准成员、3拒绝管理员、4拒绝成员 删除成员、5离开组、6、移除管理员
            switch (value)
            {
                case "1":
                    content = GetText("GP018");
                    break;
                case "2":
                    if (gm.GMR == "1")
                    {
                        content = GetText("GP048") + "<br/><a href=\"javascript:void(0);\" onclick=\"OPMember(4,'" + memberno + "')\"><img src=\"/Images/icon_friend_del.gif\" align='absmiddle' border='0'/>" + GetText("C0049") + "</a><br/><a href=\"javascript:void(0);\" onclick=\"OPMember(6,'" + memberno + "')\"><img src=\"/Images/icon_friend_down.gif\" align='absmiddle' border='0'/>" + GetText("GP227") + "</a>";
                    }
                    else
                    {
                        content = GetText("GP048");
                    }
                    break;
                case "3":
                    if (gm.GMR == "1" || gm.GMR == "2")
                    {
                        content = GetText("GP049") + "<br/><a href=\"javascript:void(0);\" onclick=\"OPMember(4,'" + memberno + "')\"><img src=\"/Images/icon_friend_del.gif\" align='absmiddle' border='0'/>" + GetText("C0049") + "</a>";
                    }
                    else
                    {
                        content = GetText("GP049");
                    }
                    break;
                case "9":
                    content = "<a href=\"javascript:void(0);\" onclick=\"OPMember(1,'" + memberno + "')\">" + GetText("GP224") + "</a>";
                    break;
                case "8":
                    content = "<a href=\"javascript:void(0);\" onclick=\"OPMember(2,'" + memberno + "')\">" + GetText("GP225") + "</a>";
                    break;
                //}
            }
            return content;
        }
    }
}
